<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册页面</title>
	</head>
	<style>
		#reg{
			width:300px;
			height:300px;
			border: 1px solid black;
			margin: 200px auto;
			padding-left: 20px;
			box-sizing: border-box;
		}
	</style>
	<body>
		<div id="reg">
			<h2>用户注册</h2>
			<p>
				<label for="username">用户名</label>
				<input type="text" id="username">
			</p>
			<p>
				<label for="username">密码</label>
				<input type="password" id="password">
			</p>
			<p>
				<label for="name">姓名</label>
				<input type="text" id="callname">
			</p>
			<div class="form-group">
				<label for="data-age" class="col-sm-2 control-label"></label>
				<label class="radio-inline">
					<input type="radio" name="sex" checked id="teacher">老师
				</label>
				<label class="radio-inline">
					<input type="radio" name="sex" id="student" checked>学生
				</label>
			</div>
			<p>
				<button id="send">注册</button>
			</p>
		</div>
		
        <script src="jquery.min.js"></script>
        <script src="url.js"></script>
		<script>
            $("#send").click(function(){
                let username = $("#username").val()
                let password = $("#password").val()
                let name = $("#callname").val()
                if(username && password && name){
                    $.ajax({
                        url:`${address}/regUser`,
                        data:{
                            username,
                            password,
							name,
							// 如果是老师为0，学生为1
                            type:$("#teacher")[0].checked ? 1 : 0
                        },
                        success(data){
                            if(data==="error"){
                                alert("注册失败")
                            }
                            else{
								alert("注册成功")
								// 注册成功后，跳转到登录页面
                                location.href = `${address}/login.html`
                            }
                        }
                    })
                }
            })
		</script>
	</body>
</html>